
package com.yuan.graduate;

import com.yuan.adapt.AdaptListUtils;
import com.yuan.application.BaseActivity;
import com.yuan.model.M请假申请;
import com.yuan.unit.AsyncDataJobHandler;
import com.yuan.unit.ToastHelper;

import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

import java.util.List;
import java.util.Map;

/**
 * 请假详情界面
 * 
 * @author YUAN
 */
@SuppressLint("HandlerLeak")
public class LeaveInfoActivity extends BaseActivity implements OnClickListener {
    private TextView leave_reason_info, leave_people_info, leave_state_info, leave_statrtime_info,
            leave_endtime_info,
            leave_alltime_info, title;
    private Button leave_canel, leave_sick;
    private Context mContext = null;
    private Handler mHandler = null;
    private int position = -1;
    private String reason, name, starttime, endtime, alltime, state;
    private int leaveid;
    List<?> list = null;
    Map<?, ?> map = null;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mContext = this;
        setContentView(R.layout.activity_leaveinfo);
        mHandler = new Handler() {
            public void handleMessage(Message msg) {
                switch (msg.what)
                {
                    case CANCELLEAVESUCCEED:
                        ToastHelper.getInstance().shortToast(mContext, "删除成功");
                        finish();
                        break;
                    case CANCELLEAVEFILLED:
                        ToastHelper.getInstance().shortToast(mContext, "删除失败");
                        break;
                    default:
                        break;
                }
            }
        };
        initView();
        writeToView();

    }

    private void writeToView() {
        // TODO Auto-generated method stub
        try {
            position = getIntent().getExtras().getInt("position");
        } catch (Exception e)
        {
            e.printStackTrace();
        }
        list = AdaptListUtils.getInstance().getAllLeaveAccountList();
        map = (Map<?, ?>) list.get(position);
        name = (String) map.get("姓名");
        starttime = (String) map.get("开始");
        endtime = (String) map.get("结束");
        alltime = "共计" + map.get("总时间") + "小时";
        state = (String) map.get("状态");
        reason = (String) map.get("请假理由");
        leaveid = (Integer) map.get("id");
        if (TextUtils.isEmpty(state)) {
            state = "目前未审批";
        }
        leave_people_info.setText(name);
        leave_state_info.setText(state);
        leave_statrtime_info.setText(starttime);
        leave_endtime_info.setText(endtime);
        leave_alltime_info.setText(alltime);
        leave_reason_info.setText(reason);
        title.setText("请假详情界面");
    }

    private void initView() {
        // TODO Auto-generated method stub
        leave_people_info = (TextView) findViewById(R.id.leave_people_info);
        leave_state_info = (TextView) findViewById(R.id.leave_state_info);
        leave_statrtime_info = (TextView) findViewById(R.id.leave_statrtime_info);
        leave_endtime_info = (TextView) findViewById(R.id.leave_endtime_info);
        leave_alltime_info = (TextView) findViewById(R.id.leave_alltime_info);
        leave_reason_info = (TextView) findViewById(R.id.leave_reason_info);
        title = (TextView) findViewById(R.id.title);
        leave_canel = (Button) findViewById(R.id.leave_canel);
        leave_sick = (Button) findViewById(R.id.leave_sick);
        leave_sick.setOnClickListener(this);
        leave_canel.setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        switch (v.getId()) {
            case R.id.leave_canel:
                if (!state.equals("目前未审批"))
                {
                    ToastHelper.getInstance().shortToast(mContext, "补课取消");
                    return;
                }
                M请假申请.getInstance().setId(leaveid);
                AsyncDataJobHandler.getInstance().cancelLeave(mHandler);
                break;
            case R.id.leave_sick:
                break;
            default:
                break;
        }
    }
}
